<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.view');

class JBSViewAssetGroups extends JView {
	function display($tpl = null) {
		$task = JRequest :: getVar('task');
		switch ($task) {
			case 'edit':
			case 'add':
				//get the assetgroups
				$assetgroup = & $this->get('Data');
				$isNew = ($assetgroup->id < 1);

				$text = $isNew ? JText :: _('New') : JText :: _('Edit');
				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText :: _('ASSET GROUP') . ': <small><small>[ ' . $text . ' ]</small></small>', 'jbschedule');
				JToolBarHelper :: save();
				if ($isNew) {
					JToolBarHelper :: cancel();
				} else {
					// for existing items the button is renamed `close`
					JToolBarHelper :: cancel('cancel', 'Close');
				}
				$this->assignRef('assetgroup', $assetgroup);

				break;

			case 'ajaxGetAll':
				// Get data from the model
				$items = & $this->get('AllData');
				$this->assignRef('items', $items);

				break;

			default:
				global $mainframe, $option;
				//initialise variables
				$db			= & JFactory::getDBO();

				//get vars
				$filter_order		= $mainframe->getUserStateFromRequest( $option.'.assetgroups.filter_order', 'filter_order', 	'name', 'cmd' );
				$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'.assetgroups.filter_order_Dir', 'filter_order_Dir', '', 'word' );
				$search 			= $mainframe->getUserStateFromRequest( $option.'.assetgroups.search', 'search', '', 'string' );
				$search 			= $db->getEscaped( trim(JString::strtolower( $search ) ) );
				$template			= $mainframe->getTemplate();

				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText :: _('Asset Groups Manager'), 'jbschedule');
				JToolBarHelper :: deleteList(JText :: _('ARE YOU SURE')); //param: 1: message 2: task to do 3: Label of the button
				JToolBarHelper :: editListX();
				JToolBarHelper :: addNewX();

				// Get data from the model
				$items      	= & $this->get( 'DataList');
				//$total      = & $this->get( 'Total');
				$pageNav 	= & $this->get( 'Pagination' );

				// table ordering
				$lists['order_Dir'] = $filter_order_Dir;
				$lists['order'] = $filter_order;

				// search filter
				$lists['search']= $search;

				$this->assignRef('lists'      	, $lists);
				$this->assignRef('pageNav' 		, $pageNav);
				$this->assignRef('template'		, $template);
				$this->assignRef('items'		, $items);

				break;
		}

		parent :: display($tpl);
	}
}